
Page({
  data:{
    love:[],
    consultName:'',
    clear:true,
    temp:true,
    temp1:false,
    placeholder:"请输入你要搜索的内容",
    onCancel:"onCancel",
    searchHistory: [],
    FindList:[],
    //  搜索的心理专家数据
    PFE:[],
    //  搜索的心理文章数据
    article:[],
    reply:[
      {
        user:""
      }
    ],
    url:'',
    losthost:''
  },
  onLoad() {
    // 页面加载时，从本地存储中读取搜索历史记录
    const searchHistory = wx.getStorageSync('searchHistory') || [];
    this.setData({
      searchHistory
    });
    const app = getApp();
        this.setData({
            url: app.globalData.URL,
            losthost:app.globalData.losthost
        })
        console.log(this.data.url)
        console.log(this.data.losthost)
        
  }, 

  shouyefindByname: function(){
    wx.request({
      url: this.data.url+"shouyefindByname",
      method:'GET',
      data:{
        consultName:this.data.consultName
      },
      success:(res)=>{
        console.log("res",res.data.data)
        this.setData({
            FindList:res.data.data,
        })
        console.log("FindList",this.data.FindList)
      },
      fail:(err)=>{
          console.log(err)
      }
    })
  },
  
  
  // 监听搜索事件
  onSearch(event) {
    const value = event.detail;
    if (value) {
      console.log('搜索内容：', value);
      // 将搜索内容添加到搜索历史记录中
      this.addSearchHistory(value);
      // 这里可以添加实际的搜索逻辑
      this.setData({
        temp:false,
        temp1:true,
        onCancel:"onCancel1",
        consultName:value
      }),
      console.log("name",this.data.consultName)
      this.shouyefindByname()
    }
  },
  // 添加搜索历史记录
  addSearchHistory(value) {
    let searchHistory = this.data.searchHistory;
    // 避免重复添加相同的搜索内容
    if (searchHistory.indexOf(value) === -1) {
      searchHistory.unshift(value);
      // 最多保存 10 条搜索历史记录
      if (searchHistory.length > 10) {
        searchHistory.pop();
      }
      this.setData({
        searchHistory
      });
      // 将搜索历史记录保存到本地存储
      wx.setStorageSync('searchHistory', searchHistory);
    }
  },
  onCancel:function(){
    wx.switchTab({
      url: '/pages/index/index/index'
    })
  },
  clear:function(){
    this.setData({
      clear:false,
      searchHistory: []
    })
     // 清空本地存储中的搜索历史记录
     wx.removeStorageSync('searchHistory');
  },
  aaa:function(){
    this.setData({
      placeholder:"请输入专家关键词/擅长",
      temp:false,
      onCancel:"onCancel1"
    })
  },
  bbb:function(){
    this.setData({
      placeholder:"请输入心理文章关键词",
      temp:false,
      onCancel:"onCancel1"
    })
  },
  ccc:function(){
    this.setData({
      placeholder:"请输入心理测试关键词",
      temp:false,
      onCancel:"onCancel1"
    })
  },
  ddd:function(){
    this.setData({
      placeholder:"请输入提问关键词",
      temp:false,
      onCancel:"onCancel1"
    })
  },
  onCancel1:function(){
    this.setData({
      temp1:false,
      temp:true,
      placeholder:"请输入你要搜索的内容",
      onCancel:"onCancel"
    })
  },
  enterconsult: function () {
      wx.switchTab({
        url: '../../consult/consult/consult',
      })
  },
  enterArticle:function () {
      wx.navigateTo({
        url: '../article/article',
      })
  },
  enterCourse:function(){
      wx.navigateTo({
        url: '../../course/onlinecourse/onlinecourse',
      })
  },
  articlede:function(e){
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../article/articledetail/articledetail?id='+id,
    })
  },
  consultde:function (e) {
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../../consult/tongyong/pyygrxx?id='+id,
    })
  },
  coursede:function (e) {
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../../course/PsychologicalCounselorCourse/Psychological Counselor Course?id='+id,
    })
  }
})